package com.tscnd.core.web.controller.log;

import java.util.HashMap;
import java.util.Map;




import javax.servlet.http.HttpServletResponse;

import net.sf.json.JSONObject;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

import com.tscnd.core.entity.BasePage;
import com.tscnd.core.exception.TSException;
import com.tscnd.core.service.log.IOptionLogService;
import com.tscnd.core.utils.AjaxUtils;

@Controller
@RequestMapping("log") 	
public class LogAction {
	
	@SuppressWarnings("unused")
	private static final Log log = LogFactory.getLog(LogAction.class);
	
	@Autowired
	private IOptionLogService optionLogService;
	
	/**
	 * 跳转到系统日志
	 * @param request
	 * @return
	 */
	@RequestMapping(value="/toSystemlog.action", method = RequestMethod.GET)
	public String toSystemlog(){
		
		return "log/systemlog";
	}

	/**
	 * 分页查询操作日志 
	 * @param response 
	 */
	@RequestMapping(value="/findOplog.do", method = RequestMethod.POST)
	public void findOplog(HttpServletResponse response,BasePage page){
		try
		{	Map<String,Object> map=new HashMap<String,Object>();
			map.put("page",page);
			Map<String,Object> rsmap= optionLogService.findPage(map);
			page=(BasePage) rsmap.get("page");
			map=new HashMap<String,Object>();
			map.put("rows",rsmap.get("list"));//数据集
			map.put("records", page.getTotalCount());//总行数
			map.put("page", page.getPage());//当前页
			map.put("total", page.getPageSize());//当前页
			JSONObject jsonObject=JSONObject.fromObject(map);
			AjaxUtils.renderJson(response, jsonObject.toString());
		} catch (TSException e)
		{
			// TODO Auto-generated catch block 
			e.printStackTrace();
		}
		
	}
	
	@ResponseBody
	@RequestMapping(value="/test.json",method=RequestMethod.GET)
	public Map<String,String> getjson(@RequestBody Map<String,String> map){
		Map<String,String> resultMap=new HashMap<String,String>();
		resultMap.put("sss", "1111");
		return resultMap;
	}
}
